package LeetCode;

import javax.security.auth.callback.CallbackHandler;
import java.security.PublicKey;
import java.util.ArrayList;
import java.util.List;

/**
 * @author zhanghao
 * @create 2023-09-06 16:38
 */
public class code17_letterCombinations {

    public static char [][] phone = {
            {'a','b','c'},
            {'d','e','f'},
            {'g','h','i'},
            {'j','k','l'},
            {'m','n','o'},
            {'p','q','r','s',},
            {'t','u','v'},
            {'w','x','y','z'}
    };

    /**
     *
     * @param digits ： 摁的数字 ： “23”
     * @return
     */
    public List<String> letterCombinations(String digits){
        List<String> ans = new ArrayList<>();
        if(digits == null || digits.length() == 0){
            return ans;
        }
        char[] str = digits.toCharArray();
        char[] path = new char[str.length];
        process(str,0,path,ans);
        return ans;
    }

    private void process(char[] str, int index, char[] path, List<String> ans) {
        if(index == str.length){
            //来到了最后的位置
            ans.add(String.valueOf(path));
        }else{
            char[] cands = phone[str[index] - '2'];
            for (char cur : cands) {
                path[index] = cur;
                process(str,index + 1,path,ans);
            }
        }
    }

    public static void main(String[] args) {
        code17_letterCombinations ss = new code17_letterCombinations();
        List<String> strings = ss.letterCombinations("23");
        System.out.println(strings);


        char[] str = {'2','3','5'};
        int index = 1;
        char[] cands = phone[str[index] - '2'];
        for (char cand : cands) {
            System.out.println(cand);
        }

    }
}
